package com.qf.homework.controller;

import com.qf.homework.entity.User;
import com.qf.homework.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * @author zehan
 * @date 2022/8/19 11:26
 */
@Controller
public class UserController {

    @Autowired
    private UserService userService;


    public User login(HttpServletRequest request){
        String account = request.getParameter("account");
        String password = request.getParameter("password");
        User loginUser = userService.login(account, password);
        return loginUser;
    }


    public void addUser(HttpServletRequest request){
        String account = request.getParameter("account");
        String password = request.getParameter("password");
        User user = User.builder().account(account).password(password).build();
        userService.addUser(user);
    }


    public void getMoney(HttpServletRequest request) throws InterruptedException {
        String account = request.getParameter("account");
        String money = request.getParameter("money");
        userService.getMoney(account,new BigDecimal(money));
    }

}
